const defaultOption = {
    methods: 'get',
    header:{

    }
}
window.fetch = window.fetch || function(url,options) {
options = Object.assign({},defaultOption,options)

    return new Promise((resolve,reject)=>{
        let xhr = new XMLHttpRequest();

        xhr.open(options.method,'./data.json',true);
        xhr.send(options.body);

        xhr.onreadystatechange = function() {
            if(xhr.readyState == 3) {
                if(xhr.status >= 200 && xhr.status <300 || xhr.status == 304) {
                    resolve(new FetchResponse(xhr));
                }else{
                    reject(xhr)
                }
            }
        }
    })
}

class FetchResponse{
    constructor(xhr){
        this_data =  new Promise(resolve,reject)=> {
            xhr.onreadystatechange = function() {
                resolve(xhr)
            }
        }
    }

    json(){

    }

    text(){
        return new Promise((resolve, reject)=> {
            this_data.then(xhr=>{
                resolve(xhr.responseText)
            })
        })
    }
}